package com.cwh.taskcenter.web.task;


import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.Response;
import com.cwh.taskcenter.task.TaskEventReportCmd;
import com.cwh.taskcenter.task.api.TaskServiceI;
import com.cwh.taskcenter.task.TaskAddCmd;
import com.cwh.taskcenter.task.TaskReceiveCmd;
import com.cwh.taskcenter.task.dto.data.TaskPageVO;
import com.cwh.taskcenter.task.dto.query.TaskListByPageQry;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author cwh
 */
@Tag(name = "任务领域", description = "任务聚合根")
@RestController
@RequestMapping("/api/task")
public class TaskController {

    @Autowired
    private TaskServiceI taskService;


    /**
     * 添加任务
     * @param taskAddCmd req
     * @return Response
     */
    @Operation(summary = "添加任务")
    @PostMapping
    public Response addTask(@RequestBody @Valid TaskAddCmd taskAddCmd) {
        return taskService.addTask(taskAddCmd);
    }

    @Operation(summary = "分页查询任务")
    @PostMapping("/page")
    public PageResponse<TaskPageVO> pageTask(@RequestBody TaskListByPageQry qry) {
        return taskService.pageTask(qry);
    }

    /**
     * 领取任务
     */
    @Operation(summary = "领取任务")
    @PostMapping("/receive")
    public Response receive(@RequestBody @Valid TaskReceiveCmd cmd) {
        return taskService.receive(cmd);
    }


    @Operation(summary = "任务事件上报")
    @PostMapping("/event/report")
    public Response eventReport(@RequestBody @Valid TaskEventReportCmd cmd) {
        return taskService.eventReport(cmd);
    }

}
